package com.xbongbong.paas.service.workflow.approveListPage.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.PaasProcessDataEntity;
import com.xbongbong.paas.domain.entity.PaasProcessTaskEntity;
import com.xbongbong.paas.domain.entity.ext.FieldPermissionEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.FlowStatusEnum;
import com.xbongbong.paas.enums.NodeTypeEnum;
import com.xbongbong.paas.enums.PlatFormEnum;
import com.xbongbong.paas.enums.ProcessSearchStatusTodoEnum;
import com.xbongbong.paas.enums.ProcessTypeEnum;
import com.xbongbong.paas.enums.TaskTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.help.FormDataHelp;
import com.xbongbong.paas.help.ProFormHelp;
import com.xbongbong.paas.help.UserInfoHelp;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.pojo.SummaryDataPoJo;
import com.xbongbong.paas.pojo.dto.ParseSingleRowDataDTO;
import com.xbongbong.paas.pojo.dto.ProcessNodeTaskGetDTO;
import com.xbongbong.paas.pojo.dto.SummaryDataDTO;
import com.xbongbong.paas.pojo.dto.UserGetDTO;
import com.xbongbong.paas.pojo.vo.LinkResultDataVO;
import com.xbongbong.paas.pojo.vo.PaasProcessNodeTaskVO;
import com.xbongbong.paas.pojo.vo.ParseSingleRowDataVO;
import com.xbongbong.paas.pojo.vo.SummaryDataVO;
import com.xbongbong.paas.pojo.vo.UserGetVO;
import com.xbongbong.paas.pojo.workflow.task.dto.WorkflowNodeTaskListDTO;
import com.xbongbong.paas.pojo.workflow.task.vo.WorkflowNodeTaskListVO;
import com.xbongbong.paas.service.workflow.approveListPage.WorkflowApproveListPageService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.helper.PageHelper;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.JsonHelperUtil;
import com.xbongbong.paas.toolbox.util.PaasDateUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.paas.util.FormDataUtil;
import com.xbongbong.paas.util.WorkflowValidateUtil;
import com.xbongbong.parent.parse.data.FormDataListAnalysisDataHelp;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.PaasStageEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.InvoiceConstant;
import com.xbongbong.saas.constant.PageConstant;
import com.xbongbong.saas.constant.ParameterConstant;
import com.xbongbong.saas.constant.StockConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.entity.WorkOrderExplainEntity;
import com.xbongbong.saas.domain.entity.WorkOrderFormEntity;
import com.xbongbong.saas.enums.InstockTypeEnum;
import com.xbongbong.saas.enums.OutstockTypeEnum;
import com.xbongbong.saas.enums.VisibleRangeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.InstockEnum;
import com.xbongbong.saas.enums.business.InvoiceEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.business.PaymentSheetEnum;
import com.xbongbong.saas.enums.business.PurchaseInvoiceEnum;
import com.xbongbong.saas.model.WorkOrderExplainModel;
import com.xbongbong.saas.model.WorkOrderFormModel;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import com.xbongbong.sys.domain.entity.DepartmentEntity;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.model.DepartmentModel;
import com.xbongbong.sys.model.UserModel;
import com.xbongbong.workflow.domain.entity.WorkflowNodeEntity;
import com.xbongbong.workflow.domain.entity.WorkflowTaskEntity;
import com.xbongbong.workflow.domain.entity.WorkflowTaskNodeEntity;
import com.xbongbong.workflow.domain.entity.WorkflowTransferDataEntity;
import com.xbongbong.workflow.domain.entity.ext.WorkflowNodeEntityExt;
import com.xbongbong.workflow.domain.entity.ext.WorkflowTaskNodeEntityExt;
import com.xbongbong.workflow.model.WorkflowNodeModel;
import com.xbongbong.workflow.model.WorkflowTaskModel;
import com.xbongbong.workflow.model.WorkflowTaskNodeModel;
import com.xbongbong.workflow.model.WorkflowTransferDataModel;
import com.xbongbong.workflow.pojo.WorkflowTransferPOJO;
import com.xbongbong.workflow.pojo.nodes.ApprovalNode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author chenpeng
 * @version 1.0
 * @date 2021-05-19 19:26
 * @description
 */
@Service
@Slf4j
public class WorkflowApproveListPageServiceImpl implements WorkflowApproveListPageService {

    @Resource
    private WorkOrderFormModel workOrderFormModel;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private WorkflowNodeModel workflowNodeModel;
    @Resource
    private WorkflowTaskModel workflowTaskModel;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private WorkOrderExplainModel workOrderExplainModel;
    @Resource
    private UserModel userModel;
    @Resource
    private DepartmentModel departmentModel;
    @Resource
    private WorkflowTaskNodeModel workflowTaskNodeModel;
    @Resource
    private ProFormHelp proFormHelp;
    @Resource
    private FormDataListAnalysisDataHelp formDataListAnalysisDataHelp;
    @Resource
    private UserInfoHelp userInfoHelp;
    @Resource
    private WorkflowTransferDataModel workflowTransferDataModel;
    @Resource
    private FormDataHelp formDataHelp;

    /**
     * 全部审批
     *
     * @param workflowNodeTaskListDTO
     */
    @Override
    public WorkflowNodeTaskListVO allList(WorkflowNodeTaskListDTO workflowNodeTaskListDTO) throws XbbException {
        WorkflowNodeTaskListVO workflowNodeTaskListVO = new WorkflowNodeTaskListVO();
        try {
            checkPermission(workflowNodeTaskListDTO);
            Map<String, Object> param = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
            getSaasBusinessType(workflowNodeTaskListDTO, param);

            //设置时间范围
            setTimeRange(workflowNodeTaskListDTO, param);
            if (StringUtil.isNotEmpty(workflowNodeTaskListDTO.getCommitUserId())) {
                param.put("creatorId", workflowNodeTaskListDTO.getCommitUserId());
            }
            //审批编号搜索
            if(StringUtil.isNotEmpty(workflowNodeTaskListDTO.getSerialNoLike())){
                param.put("serialNoLike",workflowNodeTaskListDTO.getSerialNoLike());
            }
            //标题搜索
            if(StringUtil.isNotEmpty(workflowNodeTaskListDTO.getTitleLike())){
                param.put("titleLike",workflowNodeTaskListDTO.getTitleLike());
            }
            param.put("orderByStr", " add_time desc");
            // 单据拆分兼容
            specialParams(param, workflowNodeTaskListDTO.getBusinessType());
    
            //分页查询
            PageHelper pageHelper = buildPageHelp(workflowNodeTaskListDTO, param);
            
            //查询任务表
            List<WorkflowTaskEntity> taskEntityList = workflowTaskModel.findEntities(param);
            WorkflowValidateUtil.checkQueryResult(taskEntityList, MessageConstant.PROCESS_TASK_NOT_EXIST);
            
            if (isEmptyList(workflowNodeTaskListDTO, workflowNodeTaskListVO, taskEntityList)) {
                return workflowNodeTaskListVO;
            }
            
            // 流程任务集合 processTaskMap
            List<Long> taskIdInList = new ArrayList<>();
            Map<Long, WorkflowTaskEntity> processTaskMap = new HashMap<>(taskEntityList.size());
            taskEntityList.forEach(item -> {
                taskIdInList.add(item.getId());
                processTaskMap.put(item.getId(), item);
            });
            
            // 最新流程节点任务集合 nodeTaskList
            param = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
            param.put("nodeTypeIn", Arrays.asList(NodeTypeEnum.START_PROCESS_NODE.getNodeType(), NodeTypeEnum.PROCESS_NODE.getNodeType()));
            param.put("taskTypeIn", Arrays.asList(TaskTypeEnum.UNTREATED.getType(), TaskTypeEnum.COMMIT.getType(), TaskTypeEnum.END.getType(), TaskTypeEnum.REVOKE.getType(), TaskTypeEnum.SYSTEM_COMMIT.getType(), TaskTypeEnum.AGAIN_COMMIT.getType()));
            param.put("orderByStr", "id " + SortOrder.DESC + ", update_time " + SortOrder.DESC);
            param.put("taskIdIn", taskIdInList);
            List<WorkflowTaskNodeEntityExt> nodeTaskList = workflowTaskNodeModel.getLatestNodeForList(param);
            WorkflowValidateUtil.checkQueryResult(nodeTaskList);

            // 模板节点集合 templateNodeMap
            List<Long> templateNodeIdInList = nodeTaskList.stream().map(WorkflowTaskNodeEntity::getWorkflowNodeId).collect(Collectors.toList());
            param = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
            param.put("idIn", templateNodeIdInList);
            param.remove("del");
            List<WorkflowNodeEntityExt> templateNodeList = workflowNodeModel.list(param);
            WorkflowValidateUtil.checkQueryResult(templateNodeList, MessageConstant.PROCESS_NODE_NOT_EXIST);
            
            //templateNodeList 转map
            Map<Long, WorkflowNodeEntityExt> templateNodeMap = templateNodeList.stream().collect(Collectors.toMap(WorkflowNodeEntity::getId, t -> t));
    
            // 获取任务中摘要、任务、表单数据
            List<SummaryDataVO> summaryList = getSummaryList(workflowNodeTaskListDTO, templateNodeMap, processTaskMap, nodeTaskList);
            workflowNodeTaskListVO.setList(summaryList);
            workflowNodeTaskListVO.setPageHelper(pageHelper);
            workflowNodeTaskListVO.setProcessType(workflowNodeTaskListDTO.getProcessType());
            
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("获取全部审批列表出错,platForm:" + workflowNodeTaskListDTO.getPlatform(), e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return workflowNodeTaskListVO;
    }
    
    private boolean isEmptyList(WorkflowNodeTaskListDTO workflowNodeTaskListDTO,
                                WorkflowNodeTaskListVO workflowNodeTaskListVO, List<WorkflowTaskEntity> taskList) {
        if (taskList.isEmpty()) {
            workflowNodeTaskListVO.setList(new ArrayList<>());
            int page = workflowNodeTaskListDTO.getPage() == null ? 1 : workflowNodeTaskListDTO.getPage();
            int pageSize = workflowNodeTaskListDTO.getPageSize() == null ? 20 : workflowNodeTaskListDTO.getPageSize();
            workflowNodeTaskListVO.setPageHelper(new PageHelper(page, pageSize).setRowsCount(workflowNodeTaskListVO.getList().size()));
            return true;
        }
        return false;
    }
    
    private void getSaasBusinessType(WorkflowNodeTaskListDTO workflowNodeTaskListDTO, Map<String, Object> param) {
        // SaaS业务处理
        if (Objects.equals(workflowNodeTaskListDTO.getSaasMark(), SaasMarkEnum.SAAS.getCode())) {
            // saas应用下也可能有paas的自定义表单 所以需要去掉saasMark
            workflowNodeTaskListDTO.setSaasMark(null);
            Integer saasAppType = workflowNodeTaskListDTO.getSaasAppType();
            param.remove("saasMark");
            if (Objects.equals(saasAppType, XbbRefTypeEnum.WORK_ORDER.getCode())) {
                param.put("businessType", XbbRefTypeEnum.WORK_ORDER.getCode());
            } else {
                if (Objects.isNull(workflowNodeTaskListDTO.getBusinessType())) {
                    Long appId = workflowNodeTaskListDTO.getAppId();
                    Map<String, Object> params = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                    params.put("corpid", workflowNodeTaskListDTO.getCorpid());
                    params.put("appId", appId);
                    params.put("del", 0);
                    List<PaasFormEntityExt> paasFormEntityExts = paasFormModel.list(params);
                    if (!paasFormEntityExts.isEmpty()) {
                        List<Long> formIdList = new ArrayList<>();
                        paasFormEntityExts.forEach(item -> formIdList.add(item.getId()));
                        param.put("formIdIn", formIdList);
                    }
                }
            }
        }
    }
    
    /**
     * 抄送给我的
     *
     * @param workflowNodeTaskListDTO
     */
    @Override
    public WorkflowNodeTaskListVO ccList(WorkflowNodeTaskListDTO workflowNodeTaskListDTO) throws XbbException {
        WorkflowNodeTaskListVO workflowNodeTaskListVO = new WorkflowNodeTaskListVO();
        try {
            checkPermission(workflowNodeTaskListDTO);
    
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            // 关联查询条件封装
            getCommonParamForJoinSearch(workflowNodeTaskListDTO, param);
            
            // 先根据更新时间降序，再根据id降序
            param.put("orderByStr", " a.update_time " + SortOrder.DESC + ", a.id " + SortOrder.DESC);
            param.put("a_taskType", TaskTypeEnum.CC.getType());
        
            //分页查询
            PageHelper pageHelper = buildPageHelp(workflowNodeTaskListDTO, param);
    
            List<WorkflowTaskNodeEntityExt> nodeTaskList = workflowTaskNodeModel.getJoinNodeForList(param);
            WorkflowValidateUtil.checkQueryResult(nodeTaskList);
            
            //首页跳转,所以要找到指定的,放到第一个
            IndexSkipChangePosition(workflowNodeTaskListDTO, param, nodeTaskList);
    
            param = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
            param.remove("businessType");
            
            // 分页就不需要这么多数据
            List<Long> templateNodeIdIn = new ArrayList<>();
            List<Long> taskIdIn = new ArrayList<>();
            nodeTaskList.forEach(item -> {
                taskIdIn.add(item.getTaskId());
                templateNodeIdIn.add(item.getWorkflowNodeId());
            });
            
            param.put("idIn", templateNodeIdIn);
            List<WorkflowNodeEntityExt> nodeList = workflowNodeModel.list(param);
            WorkflowValidateUtil.checkQueryResult(nodeList);
            
            param.put("idIn", taskIdIn);
            List<WorkflowTaskEntity> taskList = workflowTaskModel.findEntities(param);
            WorkflowValidateUtil.checkQueryResult(taskList);
    
            Map<Long, WorkflowTaskEntity> taskMap = taskList.stream().collect(Collectors.toMap(WorkflowTaskEntity::getId, t -> t));
            Map<Long, WorkflowNodeEntityExt> nodeMap = nodeList.stream().collect(Collectors.toMap(WorkflowNodeEntity::getId, t -> t));
    
            // 获取任务中摘要、任务、表单数据
            buildSummaryList(workflowNodeTaskListDTO, workflowNodeTaskListVO, pageHelper, nodeTaskList, taskMap, nodeMap);
    
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("获取抄送给我的审批出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return workflowNodeTaskListVO;
    }
    
    /**
     * 首页跳转,把目标信息放到第一位
     * @param workflowNodeTaskListDTO
     * @param param
     * @param nodeTaskList
     */
    private void IndexSkipChangePosition(WorkflowNodeTaskListDTO workflowNodeTaskListDTO, Map<String, Object> param, List<WorkflowTaskNodeEntityExt> nodeTaskList) {
        boolean hasNode = false;
        WorkflowTaskNodeEntityExt nodeTaskEntityExt = null;
        if (Objects.nonNull(workflowNodeTaskListDTO.getProcessNodeTaskId())) {
            for (WorkflowTaskNodeEntityExt workflowTaskNodeEntityExt : nodeTaskList) {
                if (Objects.equals(workflowTaskNodeEntityExt.getId(), workflowNodeTaskListDTO.getProcessNodeTaskId())) {
                    hasNode = true;
                    nodeTaskEntityExt = workflowTaskNodeEntityExt;
                    break;
                }
            }
        }
        if (hasNode) {
            nodeTaskList.remove(nodeTaskEntityExt);
            nodeTaskList.add(0, nodeTaskEntityExt);
        } else if (Objects.nonNull(workflowNodeTaskListDTO.getProcessNodeTaskId())) {
            param.clear();
            param.put("corpid", workflowNodeTaskListDTO.getCorpid());
            param.put("del", 0);
            param.put("id", workflowNodeTaskListDTO.getProcessNodeTaskId());
            List<WorkflowTaskNodeEntityExt> workflowTaskNodeEntityExts = workflowTaskNodeModel.findExtEntities(param);
            if (CollectionsUtil.isNotEmpty(workflowTaskNodeEntityExts)) {
                nodeTaskList.add(0, workflowTaskNodeEntityExts.get(0));
            }
        }
    }
    
    /**
     * 获取任务中摘要、任务、表单数据
     * @param workflowNodeTaskListDTO
     * @param workflowNodeTaskListVO
     * @param nodeTaskList
     * @param taskMap
     * @param nodeMap
     * @throws XbbException
     */
    private void buildSummaryList(WorkflowNodeTaskListDTO workflowNodeTaskListDTO,
                                  WorkflowNodeTaskListVO workflowNodeTaskListVO, PageHelper pageHelper,
                                  List<WorkflowTaskNodeEntityExt> nodeTaskList, Map<Long, WorkflowTaskEntity> taskMap,
                                  Map<Long, WorkflowNodeEntityExt> nodeMap) throws XbbException {
        if (nodeTaskList.isEmpty()) {
            workflowNodeTaskListVO.setList(new ArrayList<>());
        } else {
            List<SummaryDataVO> summaryList = getSummaryList(workflowNodeTaskListDTO, nodeMap, taskMap, nodeTaskList);
            workflowNodeTaskListVO.setList(summaryList);
        }
        workflowNodeTaskListVO.setPageHelper(pageHelper);
        workflowNodeTaskListVO.setProcessType(workflowNodeTaskListDTO.getProcessType());
    }
    
    @Override
    public WorkflowNodeTaskListVO todoList(WorkflowNodeTaskListDTO workflowNodeTaskListDTO) throws XbbException {
        WorkflowNodeTaskListVO workflowNodeTaskListVO = new WorkflowNodeTaskListVO();
        try {
    
            checkPermission(workflowNodeTaskListDTO);
    
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            // 关联查询条件封装
            getCommonParamForJoinSearch(workflowNodeTaskListDTO, param);

            // 先根据更新时间降序，再根据id降序
            param.put("orderByStr", " a.update_time " + SortOrder.DESC + ", a.id " + SortOrder.DESC);
            param.put("a_nodeType", NodeTypeEnum.PROCESS_NODE.getNodeType());
            
            // 审批状态筛选
            setApproveStatus(workflowNodeTaskListDTO, param);
    
            //分页查询
            PageHelper pageHelper = buildPageHelp(workflowNodeTaskListDTO, param);

            //连表查询
            if (workflowNodeTaskListDTO.getPageSize() <= PaasConstant.APPROVAL_INDEX_SIZE){
                Integer pageSize = PaasConstant.APPROVAL_INDEX_SIZE + 1;
                Integer page = workflowNodeTaskListDTO.getPage();
                if (page == null || page < 1) {
                    page = 1;
                }
                param.put("start", (page - 1) * pageSize);
                param.put("pageNum", pageSize);
            }
            List<WorkflowTaskNodeEntityExt> nodeTaskList = workflowTaskNodeModel.getJoinNodeForList(param);
            WorkflowValidateUtil.checkQueryResult(nodeTaskList);
    
            //首页跳转,所以要找到指定的,放到第一个
            IndexSkipChangePosition(workflowNodeTaskListDTO, param, nodeTaskList);

            param = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
            param.remove("businessType");
    
            // 分页就不需要这么多数据
            List<Long> templateNodeIdIn = new ArrayList<>();
            List<Long> taskIdIn = new ArrayList<>();
            nodeTaskList.forEach(item -> {
                taskIdIn.add(item.getTaskId());
                templateNodeIdIn.add(item.getWorkflowNodeId());
            });
            
            param.put("idIn", templateNodeIdIn);
            List<WorkflowNodeEntityExt> nodeList = workflowNodeModel.list(param);
            WorkflowValidateUtil.checkQueryResult(nodeList);
            
            param.put("idIn", taskIdIn);
            //这里为什么要把del删掉?
            param.remove("del");
            List<WorkflowTaskEntity> taskList = workflowTaskModel.findEntities(param);
            WorkflowValidateUtil.checkQueryResult(taskList);
            
            //taskList 转 map
            Map<Long, WorkflowTaskEntity> pageProcessTaskMap = taskList.stream().collect(Collectors.toMap(WorkflowTaskEntity::getId, t -> t));
            //nodeList 转 map
            Map<Long, WorkflowNodeEntityExt> nodeMap = nodeList.stream().collect(Collectors.toMap(WorkflowNodeEntity::getId, t -> t));
            // 获取任务中摘要、任务、表单数据
            buildSummaryList(workflowNodeTaskListDTO, workflowNodeTaskListVO, pageHelper, nodeTaskList, pageProcessTaskMap, nodeMap);
            if (workflowNodeTaskListDTO.getPageSize()  <= PaasConstant.APPROVAL_INDEX_SIZE){
                List<SummaryDataVO> summaryList = workflowNodeTaskListVO.getList();
                if (null != summaryList){
                    pageHelper.setRowsCount(summaryList.size());
                    if (summaryList.size() > PaasConstant.APPROVAL_INDEX_SIZE){
                        summaryList = summaryList.subList(0,PaasConstant.APPROVAL_INDEX_SIZE);
                        workflowNodeTaskListVO.setList(summaryList);
                    }
                    workflowNodeTaskListVO.setPageHelper(pageHelper);
                }
            }

        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("获取待办审批出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return workflowNodeTaskListVO;
    }
    
    /**
     * 审批状态筛选
     * @param workflowNodeTaskListDTO
     * @param param
     */
    private void setApproveStatus(WorkflowNodeTaskListDTO workflowNodeTaskListDTO, Map<String, Object> param) {
        //我已审批的
        if (workflowNodeTaskListDTO.getProcessType().equals(ProcessTypeEnum.HAVE_DONE.getValue())) {
            if (Objects.isNull(workflowNodeTaskListDTO.getTaskType())) {
                List<Integer> taskTypeInList = new ArrayList<>();
                taskTypeInList.add(TaskTypeEnum.COMMIT.getType());
                taskTypeInList.add(TaskTypeEnum.TRANSFER.getType());
                taskTypeInList.add(TaskTypeEnum.BACK.getType());
                taskTypeInList.add(TaskTypeEnum.END.getType());
                param.put("a_taskTypeIn", taskTypeInList);
            } else {
                param.put("a_taskType", workflowNodeTaskListDTO.getTaskType());
            }
        } else {
            //待我审批
            param.put("a_taskType", TaskTypeEnum.UNTREATED.getType());
        }
    }
    
    /**
     * 检查权限
     * @param workflowNodeTaskListDTO
     * @throws XbbException
     */
    private void checkPermission(WorkflowNodeTaskListDTO workflowNodeTaskListDTO) throws XbbException {
        Optional<Set<String>> optional = Optional.ofNullable(workflowNodeTaskListDTO)
                .map(BaseDTO::getLoginUser)
                .map(UserVO::getPermSet);
        //不存在 或者 没权限
        if (!optional.isPresent()
                || !optional.get().contains(ProPermissionAliasEnum.PROCESS_APP.getAlias())
                || !optional.get().contains(ProPermissionAliasEnum.PROCESS.getAlias())) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.HAVE_NO_PERMISSION);
        }
    }
    
    /**
     * 我提交的审批
     *
     * @param workflowNodeTaskListDTO
     */
    @Override
    public WorkflowNodeTaskListVO createList(WorkflowNodeTaskListDTO workflowNodeTaskListDTO) throws XbbException {
        WorkflowNodeTaskListVO workflowNodeTaskListVO = new WorkflowNodeTaskListVO();
        try {
            checkPermission(workflowNodeTaskListDTO);
            
            Map<String, Object> param = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
            // SaaS业务处理
            getSaasBusinessType(workflowNodeTaskListDTO, param);
            //设置时间范围
            setTimeRange(workflowNodeTaskListDTO, param);
            //审批编号搜索
            if(StringUtil.isNotEmpty(workflowNodeTaskListDTO.getSerialNoLike())){
                param.put("serialNoLike",workflowNodeTaskListDTO.getSerialNoLike());
            }
            if(StringUtil.isNotEmpty(workflowNodeTaskListDTO.getTitleLike())){
                param.put("titleLike",workflowNodeTaskListDTO.getTitleLike());
            }
            param.put("creatorId", workflowNodeTaskListDTO.getUserId());
            param.put("orderByStr", " add_time desc");
            // 单据拆分兼容处理
            specialParams(param, workflowNodeTaskListDTO.getBusinessType());
            
            //分页查询
            PageHelper pageHelper = buildPageHelp(workflowNodeTaskListDTO, param);
            
            //查询任务表
            if (workflowNodeTaskListDTO.getPageSize() <= PaasConstant.APPROVAL_INDEX_SIZE){
                Integer pageSize = PaasConstant.APPROVAL_INDEX_SIZE + 1;
                Integer page = workflowNodeTaskListDTO.getPage();
                if (page == null || page < 1) {
                    page = 1;
                }
                param.put("start", (page -1) * pageSize);
                param.put("pageNum", pageSize);
                param.remove("pageSize");
            }
            List<WorkflowTaskEntity> taskList = workflowTaskModel.findEntities(param);
            WorkflowValidateUtil.checkQueryResult(taskList, MessageConstant.PROCESS_TASK_NOT_EXIST);
            if (isEmptyList(workflowNodeTaskListDTO, workflowNodeTaskListVO, taskList)) {
                return workflowNodeTaskListVO;
            }
            
            Map<Long, WorkflowTaskEntity> processTaskMap = new HashMap<>(taskList.size());
            List<Long> taskIdInList = new ArrayList<>();
            taskList.forEach(item -> {
                taskIdInList.add(item.getId());
                processTaskMap.put(item.getId(), item);
            });

            param = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
            param.put("nodeType", NodeTypeEnum.START_PROCESS_NODE.getNodeType());
            param.put("taskIdIn", taskIdInList);
            //param.remove("creatorId");
            // 确保节点为最新节点
            param.put("orderByStr", " update_time " + SortOrder.DESC + ", id " + SortOrder.DESC);
            //param.remove("pageNum");
            //param.remove("start");
            List<WorkflowTaskNodeEntityExt> list = workflowTaskNodeModel.getLatestNodeForList(param);
            WorkflowValidateUtil.checkQueryResult(list);
    
            //首页跳转,所以要找到指定的,放到第一个
            IndexSkipChangePosition(workflowNodeTaskListDTO, param, list);
            
            List<Long> templateNodeIdIn = list.stream().map(WorkflowTaskNodeEntity::getWorkflowNodeId).collect(Collectors.toList());
            param = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
    
            param.put("idIn", templateNodeIdIn);
            //param.put("type", NodeTypeEnum.START_PROCESS_NODE.getNodeType());
            param.remove("del");
            List<WorkflowNodeEntityExt> nodeList = workflowNodeModel.list(param);
            WorkflowValidateUtil.checkQueryResult(nodeList, MessageConstant.PROCESS_NODE_NOT_EXIST);
            
            Map<Long, WorkflowNodeEntityExt> nodeMap = nodeList.stream().collect(Collectors.toMap(WorkflowNodeEntityExt::getId, t -> t));
            
            List<SummaryDataVO> summaryList = getSummaryList(workflowNodeTaskListDTO, nodeMap, processTaskMap, list);
            if (workflowNodeTaskListDTO.getPageSize() <= PaasConstant.APPROVAL_INDEX_SIZE){
                pageHelper.setRowsCount(summaryList.size());
                if (summaryList.size() > PaasConstant.APPROVAL_INDEX_SIZE){
                    summaryList = summaryList.subList(0,PaasConstant.APPROVAL_INDEX_SIZE);
                }
            }
            workflowNodeTaskListVO.setList(summaryList);
            workflowNodeTaskListVO.setPageHelper(pageHelper);
            workflowNodeTaskListVO.setProcessType(workflowNodeTaskListDTO.getProcessType());
            
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("获取我创建的流程数据出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return workflowNodeTaskListVO;
    }


    /**
     *
     * @param workflowNodeTaskListDTO   入参
     * @param nodeMap                   节点map
     * @param taskMap                   任务map
     * @param nodeTaskList              连表查询结果,得到的是tb_workflow_task_node表的结果
     * @return
     * @throws XbbException
     */
    private List<SummaryDataVO> getSummaryList(WorkflowNodeTaskListDTO workflowNodeTaskListDTO, Map<Long, WorkflowNodeEntityExt> nodeMap, Map<Long, WorkflowTaskEntity> taskMap, List<WorkflowTaskNodeEntityExt> nodeTaskList) throws XbbException {
        List<SummaryDataVO> summaryList = new ArrayList<>();
        String corpid = workflowNodeTaskListDTO.getCorpid();
        String processType = workflowNodeTaskListDTO.getProcessType();
        //工单表单
        Set<Long> workOrderIdList = new HashSet<>();
        //其他表单
        Set<Long> formIdList = new HashSet<>();
        //任务 ids
        Set<Long> taskIdList = new HashSet<>();

        //因为工单和其他表单不是同一个表, 所以要分开
        for (Map.Entry<Long, WorkflowTaskEntity> entry : taskMap.entrySet()) {
            WorkflowTaskEntity item = entry.getValue();
            taskIdList.add(entry.getKey());
            if (Objects.equals(item.getBusinessType(), XbbRefTypeEnum.WORK_ORDER.getCode())) {
                workOrderIdList.add(item.getFormId());
            } else {
                formIdList.add(item.getFormId());
            }
        }

        try {
            Map<String, Object> params = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            params.put("corpid", corpid);
            params.put("del", 0);
            params.put("idIn", workOrderIdList);
            // 表单列表 需要用到表单名称
            List<WorkOrderFormEntity> workOrderFormList = workOrderFormModel.findEntitys(params);
            WorkflowValidateUtil.checkQueryResult(workOrderFormList);

            params.put("idIn", formIdList);
            List<PaasFormEntityExt> formList = paasFormModel.list(params);
            WorkflowValidateUtil.checkQueryResult(formList);
            
            params.remove("orderByStr");

            //其他表单 转 map
            Map<String, PaasFormEntityExt> formMap = formList.stream().collect(Collectors.toMap(t -> t.getAppId() + "_" + t.getId(), t -> t));

            //再把工单的结果也汇集到map
            workOrderFormList.forEach(item -> {
                PaasFormEntityExt paasFormEntityExt = new PaasFormEntityExt();
                BeanUtil.copyProperties(item, paasFormEntityExt);
                paasFormEntityExt.setBusinessType(XbbRefTypeEnum.WORK_ORDER.getCode());
                formMap.put((paasFormEntityExt.getAppId() + "_" +paasFormEntityExt.getId()), paasFormEntityExt);
            });


            // 获取所有解释数据列表
            params.remove("idIn");
            params.remove(ParameterConstant.COLUMNS);
            params.put("formIdIn", formIdList);
            List<PaasFormExplainEntity> explainList = paasFormExplainModel.list(params);
            WorkflowValidateUtil.checkQueryResult(explainList);
            
            params.remove(ParameterConstant.COLUMNS);
            params.put("formIdIn", workOrderIdList);
            List<WorkOrderExplainEntity> workOrderExplainList = workOrderExplainModel.list(params);
            WorkflowValidateUtil.checkQueryResult(workOrderExplainList);

            //同理处理表单解释
            Map<String, PaasFormExplainEntity> explainMap =
                    explainList.stream().collect(Collectors.toMap(t -> t.getAppId() + "_" + t.getFormId(), t -> t));

            workOrderExplainList.forEach(item -> {
                PaasFormExplainEntity paasFormExplainEntity = new PaasFormExplainEntity();
                BeanUtil.copyProperties(item, paasFormExplainEntity);
                explainMap.put((paasFormExplainEntity.getAppId() + "_" + paasFormExplainEntity.getFormId()), paasFormExplainEntity);
            });


            // 用户列表
            params.remove(ParameterConstant.COLUMNS);
            params.remove("formIdIn");
            params.remove("del");
            params.put(ParameterConstant.LEAVE_MARKS, BasicConstant.ONE);
            List<UserEntity> allUser = userModel.findEntitys(params);
            WorkflowValidateUtil.checkQueryResult(allUser);
            
            //allUser 转 map
            Map<String, UserEntity> userMap = allUser.stream().collect(Collectors.toMap(UserEntity::getUserId, t -> t));

            // 部门列表
            params.remove(ParameterConstant.COLUMNS);
            List<DepartmentEntity> departmentList = departmentModel.findEntitys(params);
            WorkflowValidateUtil.checkQueryResult(departmentList);
            
            //departmentList 转 map
            Map<String, DepartmentEntity> departmentMap = departmentList.stream().collect(Collectors.toMap(t -> t.getId().toString(), t -> t));


            // 获取所有任务数据列表
            params = BeanUtil.convertBean2Map(workflowNodeTaskListDTO, true);
            params.put("taskIdIn", taskIdList);
            // 有可能有脏数据，导致流程状态和数据状态不一致，导致NPE，故删除流程状态筛选
            params.remove("flowStatus");
            // 单据拆分兼容处理
            specialParams(params, workflowNodeTaskListDTO.getBusinessType());
            // 去掉saas_need_pojo 这个对象太大，没必要
//            params.put(ParameterConstant.COLUMNS, "id,corpid,app_id,menu_id,form_id,form_data_id,template_id,task_id,flow_status,`data`,owner_id,department_id,serial_no,creator_id,add_time,update_time,del,saas_mark,business_type,sub_business_type");
    
    
            Map<Long, PaasFormDataEntityExt> processDataMap = new HashMap<>();
            //主表的数据循环查
            for (WorkflowTaskNodeEntityExt entityExt : nodeTaskList) {
                if (taskMap.containsKey(entityExt.getTaskId())) {
                    WorkflowTransferDataEntity workflowTransferDataEntity = workflowTransferDataModel.getByTaskId(entityExt.getTaskId(), corpid);

                    if (Objects.isNull(workflowTransferDataEntity)) {
                        continue;
                    }
                    //taskid:主表数据
                    WorkflowTransferPOJO workflowTransferPOJO = JSON.parseObject(workflowTransferDataEntity.getData().toJSONString(), WorkflowTransferPOJO.class);
                    PaasFormDataEntityExt paasFormDataEntityExt = new PaasFormDataEntityExt();
                    FormDataUtil.getDataSetSystemData(workflowTransferPOJO.getData().getData(), paasFormDataEntityExt);
                    setVisibleRangeData4ServiceProject(paasFormDataEntityExt, workflowTransferDataEntity.getBusinessType());
                    paasFormDataEntityExt.setId(entityExt.getDataId());
                    paasFormDataEntityExt.setDataId(entityExt.getDataId());
                    paasFormDataEntityExt.setFormId(entityExt.getFormId());
                    paasFormDataEntityExt.setAppId(entityExt.getAppId());
                    paasFormDataEntityExt.setMenuId(entityExt.getMenuId());
                    paasFormDataEntityExt.setCorpid(corpid);
                    processDataMap.put(entityExt.getTaskId(), paasFormDataEntityExt);
                }
            }
            WorkflowValidateUtil.checkQueryResult(processDataMap);
            
            ProcessNodeTaskGetDTO processNodeTaskGetDTO = new ProcessNodeTaskGetDTO();
            BeanUtil.copyProperties(workflowNodeTaskListDTO, processNodeTaskGetDTO);
            //获取待 *** 审批, 首页用
            Map<Long, List<WorkflowTaskNodeEntityExt>> indexTodoMap = buildIndexWaitForApprove(corpid, processType, taskIdList, params);
    
            for (WorkflowTaskNodeEntityExt nodeTask : nodeTaskList) {
                String key = nodeTask.getAppId() + "_" + nodeTask.getFormId();
                Long taskId = nodeTask.getTaskId();
                // 删除的菜单不需要处理
                PaasFormEntityExt paasFormEntityExt = formMap.get(key);
                if (paasFormEntityExt == null) {
                    continue;
                }
                if (!processDataMap.containsKey(taskId)) {
                    continue;
                }
                //22252 【审批】第一套测试环境（皇上），王碧云的账户 点击“抄送给我的审批”，弹出“服务器开小差”(新老数据问题)
                if (nodeMap.get(nodeTask.getWorkflowNodeId())==null){
                    continue;
                }

                SummaryDataDTO summaryDataDTO = new SummaryDataDTO();
                BeanUtil.copyProperties(workflowNodeTaskListDTO, summaryDataDTO);
                summaryDataDTO.setTaskId(taskId);
                summaryDataDTO.setMenuId(nodeTask.getMenuId());
                summaryDataDTO.setCorpid(corpid);
    
                PaasProcessDataEntity paasProcessDataEntity = new PaasProcessDataEntity();
                PaasFormDataEntityExt entityExt = processDataMap.get(taskId);
                BeanUtil.copyProperties(entityExt, paasProcessDataEntity);
                String data = JSON.toJSONString(entityExt.getData());
                paasProcessDataEntity.setData(data);
                paasProcessDataEntity.setSaasMark(paasFormEntityExt.getSaasMark());
                paasProcessDataEntity.setBusinessType(paasFormEntityExt.getBusinessType());
                //主表数据
                summaryDataDTO.setPaasProcessDataEntity(paasProcessDataEntity);
                //表单解释
                summaryDataDTO.setPaasFormExplainEntity(explainMap.get(key));
                WorkflowNodeEntityExt workflowNodeEntityExt = nodeMap.get(nodeTask.getWorkflowNodeId());
    
                //获取字段权限
                ApprovalNode approvalNode = JsonHelperUtil.parseObject(workflowNodeEntityExt.getConfigData(), ApprovalNode.class);
                List<FieldPermissionEntityExt> fieldPermission = new ArrayList<>(approvalNode.getFieldPermission().values());
                //字段权限
                summaryDataDTO.setSummaryEntityList(fieldPermission);
                
                summaryDataDTO.setUserId(workflowNodeTaskListDTO.getUserId());
                summaryDataDTO.setUserMap(userMap);
                summaryDataDTO.setDepartmentMap(departmentMap);

                WorkflowTaskEntity workflowTaskEntity = taskMap.get(taskId);
                PaasProcessTaskEntity paasProcessTaskEntity = new PaasProcessTaskEntity();
                BeanUtil.copyProperties(workflowTaskEntity, paasProcessTaskEntity);
                //任务实体
                summaryDataDTO.setPaasProcessTaskEntity(paasProcessTaskEntity);

                //获取summary和title
                SummaryDataVO summaryDataVO = getSummaryAndTitle(summaryDataDTO);
                
                
                PaasProcessNodeTaskVO paasProcessNodeTaskVO = new PaasProcessNodeTaskVO();
                BeanUtil.copyProperties(nodeTask, paasProcessNodeTaskVO);
    
                //首页审批进展卡片中，流程的会签、或签显示错误
                Optional.ofNullable(indexTodoMap)
                        .map(t -> t.get(nodeTask.getTaskId()))
                        .map(t -> t.get(0))
                        .ifPresent(t -> paasProcessNodeTaskVO.setSignType(t.getSignType()));
                
                paasProcessNodeTaskVO.setSaasMark(workflowTaskEntity.getSaasMark());
                paasProcessNodeTaskVO.setBusinessType(workflowTaskEntity.getBusinessType() == null ? 0 : workflowTaskEntity.getBusinessType());
                //设置审批意见是否必填
                
                paasProcessNodeTaskVO.setOpinionFlag(approvalNode.getOpinionFlag());
                
                paasProcessNodeTaskVO.setCreatorId(workflowTaskEntity.getCreatorId());
                // 确定详情是在哪个列表（撤回只在我提交的列表显示）
                paasProcessNodeTaskVO.setProcessType(processType);
                getUserName(processNodeTaskGetDTO, paasProcessNodeTaskVO);
                paasProcessNodeTaskVO.setTaskTypeMemo(ProcessSearchStatusTodoEnum.getStatusMemo(paasProcessNodeTaskVO.getTaskType()));
                TaskTypeEnum typeEnum = TaskTypeEnum.getTaskTypeEnum(paasProcessNodeTaskVO.getTaskType());
                if (typeEnum != null) {
                    paasProcessNodeTaskVO.setColor(typeEnum.getColor());
                }
                UserVO creatorUser = paasProcessNodeTaskVO.getCreatorUser();
                if (Objects.equals(paasFormEntityExt.getBusinessType(), XbbRefTypeEnum.INVOICE.getCode())) {
                    paasFormEntityExt.setName(XbbRefTypeEnum.INVOICE.getName());
                }
                
                //后缀
                String suffix = I18nMessageUtil.getMessage(CommonConstant.OF) + paasFormEntityExt.getName() + I18nMessageUtil.getMessage(I18nStringConstant.APPROVAL);
                if (creatorUser == null) {
                    summaryDataVO.setTitle("***"+ suffix);
                } else {
                    summaryDataVO.setTitle(creatorUser.getName() + suffix);
                }
                if (StringUtil.isNotEmpty(nodeTask.getTitle())) {
                    summaryDataVO.setTitle(nodeTask.getTitle());
                }

                summaryDataVO.setProcessNodeTask(paasProcessNodeTaskVO);

                //入库单操作
                otherOperationInOtherInstock(processDataMap, taskId, paasFormEntityExt, summaryDataVO);
                summaryList.add(summaryDataVO);

                // 当前最新审批中的节点的负责人列表 首页用
                buildIndexLatestApproveResponsibleList(workflowNodeTaskListDTO, processType, userMap, indexTodoMap, nodeTask, summaryDataVO);


            }
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("工作流获取任务中摘要、任务、表单数据出错，", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return summaryList;
    }

    /**
     * 设置可见范围的可见人可见部门数据 （审批左侧列表的摘要）
     * @param paasFormDataEntityExt
     * @param businessType
     */
    private void setVisibleRangeData4ServiceProject(PaasFormDataEntityExt paasFormDataEntityExt, Integer businessType) {
        if (!Objects.equals(XbbRefTypeEnum.SERVICE_PROJECT.getCode(), businessType)) {
            return;
        }
        JSONObject data = paasFormDataEntityExt.getData();
        data.put(VisibleRangeEnum.VISIBLE_USER.getAttr(), data.get(FieldTypeEnum.OWNERID.getAlias()));
        data.put(VisibleRangeEnum.VISIBLE_DEPT.getAttr(), data.get(FieldTypeEnum.COUSERID.getAlias()));
    }

    private void otherOperationInOtherInstock(Map<Long, PaasFormDataEntityExt> processDataMap, Long taskId, PaasFormEntityExt paasFormEntityExt, SummaryDataVO summaryDataVO) {
        if (Objects.equals(paasFormEntityExt.getBusinessType(), XbbRefTypeEnum.OTHER_INSTOCK.getCode())) {
            PaasFormDataEntityExt paasFormDataEntityExt = processDataMap.get(taskId);
            JSONObject processData = paasFormDataEntityExt.getData();
            List<SummaryDataPoJo> dataPoJos = summaryDataVO.getSummaryList();
            for (SummaryDataPoJo summaryDataPoJo : dataPoJos) {
                if (!Objects.equals(summaryDataPoJo.getAttr(), InstockEnum.REF_ID.getAttr())) {
                    continue;
                }
                Integer type = processData.getInteger(InstockEnum.TYPE.getAttr());
                if (Objects.equals(InstockTypeEnum.OTHER_INSTOCK.getCode(), type)) {
                    summaryDataPoJo.setValue(Collections.singletonList(I18nMessageUtil.getMessage(CommonConstant.NOTHING)));
                }
            }
        }
    }
    
    /**
     * 待 *** 审批 首页用
     * @param corpid
     * @param processType
     * @param taskIdList
     * @param params
     * @return
     * @throws XbbException
     */
    private Map<Long, List<WorkflowTaskNodeEntityExt>> buildIndexWaitForApprove(String corpid, String processType,
                                                                                Set<Long> taskIdList,
                                                                                Map<String, Object> params) throws XbbException {
        
        Map<Long, List<WorkflowTaskNodeEntityExt>> indexTodoMap = new HashMap<>();
        if (Objects.equals(processType, ProcessTypeEnum.CREATE.getValue())) {
            params.clear();
            params.put("corpid", corpid);
            params.put("taskIdIn", taskIdList);
            params.put("taskType", TaskTypeEnum.UNTREATED.getType());
            params.put("del", 0);
            List<WorkflowTaskNodeEntityExt> taskNodeList = workflowTaskNodeModel.findExtEntities(params);
            WorkflowValidateUtil.checkQueryResult(taskNodeList);
            
            
//                taskNodeList.forEach(item -> {
//                    List<WorkflowTaskNodeEntityExt> extList = new ArrayList<>();
//                    if (indexTodoMap.containsKey(item.getTaskId())) {
//                        extList.addAll(indexTodoMap.get(item.getTaskId()));
//                        extList.add(item);
//                        indexTodoMap.put(item.getTaskId(), extList);
//                    } else {
//                        extList.add(item);
//                        indexTodoMap.put(item.getTaskId(), extList);
//                    }
//                });
            
            //过滤掉taskid 为null的, 根据taskid 来区分
            indexTodoMap = taskNodeList.stream().collect(Collectors.groupingBy(WorkflowTaskNodeEntity::getTaskId));

        }
        return indexTodoMap;
    }
    
    private SummaryDataVO getSummaryAndTitle(SummaryDataDTO summaryDataDTO) throws XbbException {
        SummaryDataVO summaryDataVO = new SummaryDataVO();
        try {
            //主表数据
            PaasProcessDataEntity paasProcessDataEntity = summaryDataDTO.getPaasProcessDataEntity();
            //任务实体
            PaasProcessTaskEntity paasProcessTaskEntity = summaryDataDTO.getPaasProcessTaskEntity();
            Map<String, UserEntity> userMap = summaryDataDTO.getUserMap();
            Map<String, DepartmentEntity> departmentMap = summaryDataDTO.getDepartmentMap();
            
            summaryDataVO.setFlowStatusDesc(FlowStatusEnum.getMemoByType(paasProcessTaskEntity.getFlowStatus()));
            summaryDataVO.setFlowStatus(paasProcessTaskEntity.getFlowStatus());
            summaryDataVO.setFlowAddTime(paasProcessTaskEntity.getAddTime());
            FlowStatusEnum flowStatusEnum = FlowStatusEnum.getFlowStatusEnumByType(paasProcessTaskEntity.getFlowStatus());
            if (flowStatusEnum != null) {
                summaryDataVO.setColor(flowStatusEnum.getColor());
            }
            //字段解释
            PaasFormExplainEntity paasFormExplainEntity = summaryDataDTO.getPaasFormExplainEntity();
            
            // 标签字段列表
            List<FieldAttrEntity> explainArray = JSON.parseArray(paasFormExplainEntity.getExplains(), FieldAttrEntity.class);
            if (explainArray == null) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
            }
            Map<String, FieldAttrEntity> explainMap = new HashMap<>(explainArray.size());
            // 数据字典需要转换下拉框
            if (Objects.equals(paasProcessDataEntity.getSaasMark(), SaasMarkEnum.SAAS.getCode())) {
                int i = 0;
                for (FieldAttrEntity fieldAttrEntity : explainArray) {
                    List<ItemPoJo> itemList = proFormHelp.getItem(fieldAttrEntity, paasProcessDataEntity.getBusinessType(), paasProcessDataEntity.getCorpid(), paasProcessDataEntity.getFormId());
                    fieldAttrEntity.setItems(itemList);
                    explainArray.set(i, fieldAttrEntity);
                    i++;
                }
            }
            
            for (FieldAttrEntity fieldAttrEntity : explainArray) {
                explainMap.put(fieldAttrEntity.getAttr(), fieldAttrEntity);
            }
            JSONObject dataJsonObject = JSON.parseObject(paasProcessDataEntity.getData());
            // 设置创建者
            dataJsonObject.put(FieldTypeEnum.ADDTIME.getAlias(), paasProcessDataEntity.getAddTime());
            dataJsonObject.put(FieldTypeEnum.UPDATETIME.getAlias(), paasProcessDataEntity.getUpdateTime());
            dataJsonObject.put(FieldTypeEnum.SERIALNO.getAlias(), paasProcessDataEntity.getSerialNo());
            dataJsonObject.put(FieldTypeEnum.CREATORID.getAlias(), paasProcessDataEntity.getCreatorId());
            dataJsonObject.put(FieldTypeEnum.DEPARTMENTID.getAlias(), paasProcessDataEntity.getDepartmentId());
            
            //  获取用户和部门容器 解析paas的特殊数据 end
            ParseSingleRowDataDTO parseSingleRowDataDTO = new ParseSingleRowDataDTO();
            BeanUtil.copyProperties(summaryDataDTO, parseSingleRowDataDTO);
            BeanUtil.copyProperties(paasProcessDataEntity, parseSingleRowDataDTO);
            parseSingleRowDataDTO.setExplainMap(explainMap);
            parseSingleRowDataDTO.setUserMap(userMap);
            parseSingleRowDataDTO.setDepartmentMap(departmentMap);
            parseSingleRowDataDTO.setIsProcess(true);
            // 兼容老数据，data没有ownId
            if (Objects.isNull(dataJsonObject.get(FieldTypeEnum.OWNERID.getAlias()))) {
                dataJsonObject.put(FieldTypeEnum.OWNERID.getAlias(), Collections.singletonList(paasProcessDataEntity.getOwnerId()));
            } else if (dataJsonObject.get(FieldTypeEnum.OWNERID.getAlias()) instanceof String) {
                dataJsonObject.put(FieldTypeEnum.OWNERID.getAlias(), Collections.singletonList(dataJsonObject.getString(FieldTypeEnum.OWNERID.getAlias())));
            }
            JSONObject jsonObject = new JSONObject();
            JSONArray summaryJsonArray = new JSONArray();
            List<FieldPermissionEntityExt> fieldPermissionList = summaryDataDTO.getSummaryEntityList();
    
            //*****************************收款单,回款单的特殊逻辑
            boolean invoiceFlag = Objects.equals(paasProcessDataEntity.getBusinessType(), XbbRefTypeEnum.INVOICE.getCode()) || Objects.equals(paasProcessDataEntity.getBusinessType(), XbbRefTypeEnum.PURCHASE_INVOICE.getCode());
            if (invoiceFlag) {
                String originIdAttr = "";
                if (Objects.equals(paasProcessDataEntity.getBusinessType(), XbbRefTypeEnum.INVOICE.getCode())) {
                    originIdAttr = InvoiceEnum.ORIGIN_ID.getAttr();
                } else if (Objects.equals(paasProcessDataEntity.getBusinessType(), XbbRefTypeEnum.PURCHASE_INVOICE.getCode())) {
                    originIdAttr = PurchaseInvoiceEnum.ORIGIN_ID.getAttr();
                }
                if (dataJsonObject.containsKey(originIdAttr)) {
                    String originId = null;
                    if (Objects.equals(paasProcessDataEntity.getBusinessType(), XbbRefTypeEnum.INVOICE.getCode())) {
                        originId = dataJsonObject.getString(InvoiceEnum.ORIGIN_ID.getAttr());
                    } else if (Objects.equals(paasProcessDataEntity.getBusinessType(), XbbRefTypeEnum.PURCHASE_INVOICE.getCode())) {
                        originId = dataJsonObject.getString(PurchaseInvoiceEnum.ORIGIN_ID.getAttr());
                    }
                    if (Objects.nonNull(originId)) {
                        long originIdLong = Long.parseLong(originId);
                        if (originIdLong > BasicConstant.ZERO) {
                            if (explainMap.size() > BasicConstant.ONE) {
                                for (Map.Entry<String, FieldAttrEntity> it : explainMap.entrySet()) {
                                    FieldAttrEntity fieldAttrEntity = it.getValue();
                                    if (Objects.equals(fieldAttrEntity.getSaasAttr(),
                                            InvoiceEnum.TOTAL_MONEY.getSaasAttr())) {
                                        fieldAttrEntity.setAttrName(InvoiceConstant.REDSTRING + fieldAttrEntity.getAttrName());
                                    }
                                }
                            }
    
                            boolean isContains = Arrays.asList(XbbRefTypeEnum.PURCHASE_INVOICE.getCode(),
                                    XbbRefTypeEnum.INVOICE.getCode()).contains(paasProcessDataEntity.getBusinessType());
    
                            if (originIdLong > 0L && isContains) {
                                if(Objects.equals(paasProcessDataEntity.getBusinessType(),XbbRefTypeEnum.PURCHASE_INVOICE.getCode())){
                                    double invoiceAmount = dataJsonObject.getDouble(PurchaseInvoiceEnum.TOTAL_MONEY.getAttr());
                                    dataJsonObject.put(PurchaseInvoiceEnum.TOTAL_MONEY.getAttr(), -invoiceAmount);
                                }else if(Objects.equals(paasProcessDataEntity.getBusinessType(),XbbRefTypeEnum.INVOICE.getCode())){
                                    double invoiceAmount = dataJsonObject.getDouble(InvoiceEnum.TOTAL_MONEY.getAttr());
                                    dataJsonObject.put(InvoiceEnum.TOTAL_MONEY.getAttr(), -invoiceAmount);
                                }
                            }
                        }
                    }
                }
            }
            
            if (Objects.equals(paasProcessDataEntity.getBusinessType(), XbbRefTypeEnum.PAYMENT_SHEET.getCode())) {
                //如果是回款单，则移除回款计划摘要
                for (FieldPermissionEntityExt s : fieldPermissionList) {
                    // 检索摘要
                    handleSummaryDataPojo(PaymentSheetEnum.PAYMENT.getAttr(), summaryJsonArray, s, jsonObject, dataJsonObject, explainMap);
                }
            }  else if (Objects.equals(paasProcessDataEntity.getBusinessType(), XbbRefTypeEnum.PAY_SHEET.getCode())) {
                //如果是付款单，则移除付款计划摘要
                for (FieldPermissionEntityExt s : fieldPermissionList) {
                    // 检索摘要
                    handleSummaryDataPojo(PaySheetEnum.PAY_PLAN.getAttr(), summaryJsonArray, s, jsonObject, dataJsonObject, explainMap);
                }
            } else {
                for (FieldPermissionEntityExt s : fieldPermissionList) {
                    handleSummaryDataPojo(null, summaryJsonArray, s, jsonObject, dataJsonObject, explainMap);
                }
            }
            
            parseSingleRowDataDTO.setDataJsonObject(jsonObject);
            //*****************************
            
            ParseSingleRowDataVO parseSingleRowDataVO = formDataListAnalysisDataHelp.parseSingleRowData(parseSingleRowDataDTO);
            if (Objects.isNull(parseSingleRowDataVO)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.PARSE_SINGLE_ROW_DATA_FAILED);
            }
            LinkResultDataVO linkResultDataVO = parseSingleRowDataVO.getLinkResultDataVO();
            linkResultDataVO.setUserMap(userMap);
            linkResultDataVO.setDepartmentMap(departmentMap);
            dataJsonObject = parseSingleRowDataVO.getResult();

            PaasFormDataEntityExt paasFormDataEntityExt = new PaasFormDataEntityExt();
            BeanUtil.copyProperties(paasProcessDataEntity, paasFormDataEntityExt);
            List<SummaryDataPoJo> summaryList = ExplainUtil.getSummaryList(summaryJsonArray, dataJsonObject, explainMap, paasFormDataEntityExt);
            
            summaryDataVO.setSummaryList(summaryList);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("查询摘要数据getSummaryAndTitle()出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return summaryDataVO;
    }
    
    /**
     * 处理摘要
     * @param removeAttr 要移除的摘要字段
     * @param summaryJsonArray 摘要
     * @param fieldPermissionEntityExt 字段权限实体
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    private void handleSummaryDataPojo(String removeAttr, JSONArray summaryJsonArray, FieldPermissionEntityExt fieldPermissionEntityExt, JSONObject jsonObject, JSONObject dataJsonObject, Map<String, FieldAttrEntity> explainMap) throws XbbException {
        if (Objects.equals(removeAttr, fieldPermissionEntityExt.getAttr())) {
            return;
        }
        // 检索摘要
        boolean summaryFlag = (fieldPermissionEntityExt.getSummary() != null && Objects.equals(fieldPermissionEntityExt.getSummary(), 1)) && (fieldPermissionEntityExt.getVisible() != null && Objects.equals(fieldPermissionEntityExt.getVisible(), 1));
        if (summaryFlag) {
            SummaryDataPoJo summaryDataPoJo = new SummaryDataPoJo();
            summaryDataPoJo.setFieldType(fieldPermissionEntityExt.getFieldType());
            summaryDataPoJo.setAttr(fieldPermissionEntityExt.getAttr());
            jsonObject.put(fieldPermissionEntityExt.getAttr(), dataJsonObject.get(fieldPermissionEntityExt.getAttr()));
            if (Objects.nonNull(explainMap.get(fieldPermissionEntityExt.getAttr())) &&
                        (Objects.equals(explainMap.get(fieldPermissionEntityExt.getAttr()).getFieldType(), FieldTypeEnum.LINK_BUSINESS_MULTI.getType()) || Objects.equals(explainMap.get(fieldPermissionEntityExt.getAttr()).getFieldType(), FieldTypeEnum.LINK_BUSINESS_SINGLE.getType()) || Objects.equals(explainMap.get(fieldPermissionEntityExt.getAttr()).getFieldType(), FieldTypeEnum.USER.getType()))) {
                jsonObject.put(explainMap.get(fieldPermissionEntityExt.getAttr()).getLinkedText(), dataJsonObject.get((explainMap.get(fieldPermissionEntityExt.getAttr()).getLinkedText())));
            }
            summaryJsonArray.add(summaryDataPoJo);
        } else {
            Long stageProcessId = FastJsonHelper.getLongOrDefaultFromFormData(dataJsonObject, PaasStageEnum.STAGE_PROCESS_ID.getAttr(), BasicConstant.ZERO_LONG);
            if (!Objects.equals(stageProcessId, BasicConstant.ZERO_LONG)) {
                jsonObject.put(PaasStageEnum.STAGE_PROCESS_ID.getAttr(), dataJsonObject.get(PaasStageEnum.STAGE_PROCESS_ID.getAttr()));
            }
        }
    }

    /**
     * 当前最新审批中的节点的负责人列表 首页用
     * @param workflowNodeTaskListDTO
     * @param processType
     * @param userMap
     * @param indexTodoMap
     * @param nodeTask
     * @param summaryDataVO
     */
    private void buildIndexLatestApproveResponsibleList(WorkflowNodeTaskListDTO workflowNodeTaskListDTO, String processType, Map<String, UserEntity> userMap, Map<Long, List<WorkflowTaskNodeEntityExt>> indexTodoMap, WorkflowTaskNodeEntityExt nodeTask, SummaryDataVO summaryDataVO) {
        if (Objects.equals(processType, ProcessTypeEnum.CREATE.getValue())) {
            List<WorkflowTaskNodeEntityExt> taskEntityExt = indexTodoMap.get(nodeTask.getTaskId());
            List<UserEntity> userList = new ArrayList<>();
            if (taskEntityExt != null) {
                taskEntityExt.forEach(item -> {
                    if (userMap.containsKey(item.getUserId())) {
                        userList.add(userMap.get(item.getUserId()));
                    }
                });
            }

            //设置名单列表
            List<Object> userNameList = new ArrayList<>();
            boolean isWeb = Objects.equals(workflowNodeTaskListDTO.getPlatform(), PlatFormEnum.WEB.getValue());
            for (UserEntity user : userList) {
                if (isWeb) {
                    userNameList.add(user.getName());
                } else {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put(StringConstant.SAAS_LINK_BUSINESS_ID, user.getUserId());
                    jsonObject.put(StringConstant.SAAS_LINK_BUSINESS_NAME, user.getName());
                    userNameList.add(jsonObject);
                }
            }
            summaryDataVO.setLatestApproveUserList(userNameList);
        }
    }

    /**
     * 获取用户名称
     *
     * @param processNodeTaskGetDTO
     * @param paasProcessNodeTaskVO
     * @throws XbbException
     */
    private void getUserName(ProcessNodeTaskGetDTO processNodeTaskGetDTO, PaasProcessNodeTaskVO paasProcessNodeTaskVO) throws XbbException {
        try {
            UserGetDTO userGetDTO = new UserGetDTO();
            BeanUtil.copyProperties(processNodeTaskGetDTO, userGetDTO);
            List<String> userIdsList = new ArrayList<>();
            userIdsList.add(paasProcessNodeTaskVO.getCreatorId());
            userIdsList.add(paasProcessNodeTaskVO.getUserId());
            userIdsList.add(paasProcessNodeTaskVO.getTransferUserId());
            userGetDTO.setTargetUserId(userIdsList);
            UserGetVO userGetVO = userInfoHelp.getUserInfoByTargetUserId(userGetDTO);
            List<UserEntity> userEntities = userModel.findEntitysByUserIds(userIdsList, paasProcessNodeTaskVO.getCorpid());

            if (CollectionUtils.isEmpty(userEntities)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.USER_NOT_EXIST);
            }
            List<UserVO> userList = userGetVO.getUserList();
            Map<String, UserVO> userVOMap = new HashMap<>(userList.size());
            userList.forEach((item) -> userVOMap.put(item.getUserId(), item));

            paasProcessNodeTaskVO.setCreatorUser(userVOMap.get(paasProcessNodeTaskVO.getCreatorId()));
            paasProcessNodeTaskVO.setOperatorUser(userVOMap.get(paasProcessNodeTaskVO.getUserId()));
            if (StringUtil.isNotEmpty(paasProcessNodeTaskVO.getTransferUserId())) {
                paasProcessNodeTaskVO.setTransferUser(userVOMap.get(paasProcessNodeTaskVO.getTransferUserId()));
            }
            if (StringUtil.isNotEmpty(paasProcessNodeTaskVO.getRevokeUserId())) {
                paasProcessNodeTaskVO.setRevokeUser(userVOMap.get(paasProcessNodeTaskVO.getRevokeUserId()));
            }
        
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("工作流获取用户名称失败", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
    }


    /**
     * @Description: 单据拆分后 审批筛选老数据兼容
     * @Param: [param, businessType]
     * @return: void
     * @Author: cyy
     * @Date: 2019/12/6
     */
    private void specialParams(Map<String, Object> param, Integer businessType) {
        List<Integer> typeEnumInteger;
        if (StockConstant.INSTOCK_TYPE_LIST.contains(businessType)) {
            typeEnumInteger = InstockTypeEnum.getInstockTypeEnumsByStockBusinessType(businessType);
            param.put("stockTypeIn",typeEnumInteger);
        }
        if (StockConstant.OUTSTOCK_TYPE_LIST.contains(businessType)){
            typeEnumInteger = OutstockTypeEnum.getOutstockTypeEnumsByStockBusinessType(businessType);
            param.put("stockTypeIn",typeEnumInteger);
        }
        if (StockConstant.EXCLUDE_INSTOCK_TYPE_LIST.contains(businessType)){
            typeEnumInteger = InstockTypeEnum.getInstockTypeEnumsByStockBusinessType(businessType);
            param.put("stockTypeIn",typeEnumInteger);

            List<Integer> businessTypeIn = Arrays.asList(XbbRefTypeEnum.OTHER_INSTOCK.getCode(),businessType);
            param.put("businessTypeIn",businessTypeIn);
            param.remove("businessType");
        }
        if (StockConstant.EXCLUDE_OUTSTOCK_TYPE_LIST.contains(businessType)){
            typeEnumInteger = OutstockTypeEnum.getOutstockTypeEnumsByStockBusinessType(businessType);
            param.put("stockTypeIn",typeEnumInteger);

            List<Integer> businessTypeIn = Arrays.asList(XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(),businessType);
            param.put("businessTypeIn",businessTypeIn);
            param.remove("businessType");
        }
    }

    /**
     * 构建查询param
     * @param workflowNodeTaskListDTO
     * @param param
     * @throws XbbException
     */
    private void getCommonParamForJoinSearch(WorkflowNodeTaskListDTO workflowNodeTaskListDTO, Map<String, Object> param) throws XbbException {
        String corpid = workflowNodeTaskListDTO.getCorpid();
        Integer businessType = workflowNodeTaskListDTO.getBusinessType();
        param.put("a_del", 0);
        param.put("b_del", 0);
        param.put("a_corpid", corpid);
        param.put("b_corpid", corpid);
        param.put("a_appId", workflowNodeTaskListDTO.getAppId());
        param.put("a_menuId", workflowNodeTaskListDTO.getMenuId());
        param.put("a_userId", workflowNodeTaskListDTO.getUserId());
        if (StringUtil.isNotEmpty(workflowNodeTaskListDTO.getCommitUserId())) {
            param.put("b_creatorId", workflowNodeTaskListDTO.getCommitUserId());
        }
        if (StringUtil.isNotEmpty(workflowNodeTaskListDTO.getSerialNoLike())) {
            param.put("a_serialNoLike", workflowNodeTaskListDTO.getSerialNoLike());
        }
        if (StringUtil.isNotEmpty(workflowNodeTaskListDTO.getTitleLike())) {
            param.put("a_titleLike", workflowNodeTaskListDTO.getTitleLike());
        }
        // 应用和表单筛选处理
        if (Objects.equals(workflowNodeTaskListDTO.getSaasMark(), SaasMarkEnum.SAAS.getCode())) {
            // saas应用下也可能有paas的自定义表单 所以需要去掉saasMark
            workflowNodeTaskListDTO.setSaasMark(null);
            Integer saasAppType = workflowNodeTaskListDTO.getSaasAppType();
            param.remove("saasMark");
            Map<String, Object> params = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            if (Objects.equals(saasAppType, XbbRefTypeEnum.WORK_ORDER.getCode()) || Objects.equals(businessType, XbbRefTypeEnum.WORK_ORDER.getCode())) {
                params.put("corpid", workflowNodeTaskListDTO.getCorpid());
                params.put("appId", workflowNodeTaskListDTO.getAppId());
                params.put("del", 0);
                List<WorkOrderFormEntity> workOrderFormEntities = workOrderFormModel.findEntitys(params);
                if (null != workOrderFormEntities) {
                    List<Long> formIdList = new ArrayList<>();
                    workOrderFormEntities.forEach(item -> formIdList.add(item.getId()));
                    param.put("a_formIdIn", formIdList);
                }
            } else {
                params.put("corpid", workflowNodeTaskListDTO.getCorpid());
                params.put("appId", workflowNodeTaskListDTO.getAppId());
                params.put("del", 0);
                if (StockConstant.EXCLUDE_INSTOCK_TYPE_LIST.contains(businessType)) {
                    List<Integer> businessTypeIn = Arrays.asList(XbbRefTypeEnum.OTHER_INSTOCK.getCode(), businessType);
                    params.put("businessTypeList", businessTypeIn);
                } else if (StockConstant.EXCLUDE_OUTSTOCK_TYPE_LIST.contains(businessType)) {
                    List<Integer> businessTypeIn = Arrays.asList(XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(), businessType);
                    params.put("businessTypeList", businessTypeIn);
                } else {
                    params.put("businessType", businessType);
                }
                List<PaasFormEntityExt> paasFormEntityExts = paasFormModel.list(params);
                if (null != paasFormEntityExts) {
                    List<Long> formIdList = new ArrayList<>();
                    paasFormEntityExts.forEach(item -> formIdList.add(item.getId()));
                    param.put("a_formIdIn", formIdList);
                }
            }
        }

        // 不知道干啥的，Mapper里也去掉了
//        List<Integer> typeEnumInteger;
//        if (StockConstant.INSTOCK_TYPE_LIST.contains(businessType)) {
//            typeEnumInteger = InstockTypeEnum.getInstockTypeEnumsByStockBusinessType(businessType);
//            param.put("b_stockTypeIn", typeEnumInteger);
//        } else if (StockConstant.OUTSTOCK_TYPE_LIST.contains(businessType)) {
//            typeEnumInteger = OutstockTypeEnum.getOutstockTypeEnumsByStockBusinessType(businessType);
//            param.put("b_stockTypeIn", typeEnumInteger);
//        }
        // 提交时间筛选
        if (Objects.nonNull(workflowNodeTaskListDTO.getCommitTime())) {
            if (workflowNodeTaskListDTO.getCommitTime().size() == BasicConstant.ONE) {
                List<Object> commitTime = PaasDateUtil.computeTime(workflowNodeTaskListDTO.getCommitTime());
                Long startTime = Long.valueOf(commitTime.get(0).toString());
                Long endTime = Long.valueOf(commitTime.get(1).toString());
                param.put("b_startTime", startTime);
                param.put("b_endTime", endTime);
            } else if (workflowNodeTaskListDTO.getCommitTime().size() == BasicConstant.TWO) {
                long startTime = Long.parseLong(workflowNodeTaskListDTO.getCommitTime().get(0).toString());
                long endTime = Long.parseLong(workflowNodeTaskListDTO.getCommitTime().get(1).toString());
                param.put("b_startTime", startTime / 1000);
                param.put("b_endTime", endTime / 1000);
            }
        }
        if (Objects.nonNull(workflowNodeTaskListDTO.getFlowStatus())) {
            param.put("b_flowStatus", workflowNodeTaskListDTO.getFlowStatus());
        }
    }
    
    /**
     * 设置时间范围搜索
     * @param workflowNodeTaskListDTO
     * @param param
     * @throws XbbException
     */
    private void setTimeRange(WorkflowNodeTaskListDTO workflowNodeTaskListDTO, Map<String, Object> param) throws XbbException {
        if (workflowNodeTaskListDTO.getCommitTime().size() == BasicConstant.ONE) {
            List<Object> commitTime = PaasDateUtil.computeTime(workflowNodeTaskListDTO.getCommitTime());
            Long startTime = Long.valueOf(commitTime.get(0).toString());
            Long endTime = Long.valueOf(commitTime.get(1).toString());
            param.put("startTime", startTime);
            param.put("endTime", endTime);
        } else if (workflowNodeTaskListDTO.getCommitTime().size() == BasicConstant.TWO) {
            Long startTime = Long.valueOf(workflowNodeTaskListDTO.getCommitTime().get(0).toString());
            Long endTime = Long.valueOf(workflowNodeTaskListDTO.getCommitTime().get(1).toString());
            param.put("startTime", startTime / 1000);
            param.put("endTime", endTime / 1000);
            // 前端说时间筛选前端做兼容
            /*if (Objects.equals(startTime, endTime)) {
                param.put("endTime", endTime / 1000 + 86400);
            }*/
        }
    }
    
    /**
     * 设置分页查询参数
     * @param workflowNodeTaskListDTO
     * @param param
     * @return
     */
    private PageHelper buildPageHelp(WorkflowNodeTaskListDTO workflowNodeTaskListDTO, Map<String, Object> param) {
        Integer page = workflowNodeTaskListDTO.getPage();
        Integer pageSize = workflowNodeTaskListDTO.getPageSize();
        if (page == null || page < 1) {
            page = 1;
        }
        if (pageSize == null || pageSize < 1) {
            pageSize = PageConstant.DEFAULT_PAGE_SIZE;
        }
        param.put("start", (page - 1) * pageSize);
        param.put("pageNum", pageSize);
        return new PageHelper(page, pageSize);
    }
}
